﻿using System;
using System.Collections.Generic;
using Ext.Net;
using BLL;
using Model;
using System.Xml;
using System.Xml.Xsl;

namespace Web.View.t203Menu
{
    public partial class Default : UIPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //绑定Grid
        protected void t203_DataBind(object sender, StoreRefreshDataEventArgs e)
        {
            t203Mgr mgr = new t203Mgr();
            e.Total = int.Parse(mgr.GetRecordCount_t203(e.Parameters[t203_Filter.ParamPrefix]));
            IList<t203> list = mgr.FindAllByPage_t203(e.Start.ToString(), e.Limit.ToString(), e.Parameters[t203_Filter.ParamPrefix]);
            t203_MainStore.DataSource = list;
            t203_MainStore.DataBind();
        }
        //删除数据
        protected void BtnDel_Click(object sender, DirectEventArgs e)
        {
            t203Mgr mgr = new t203Mgr();
            RowSelectionModel sm = t203_Grid.SelectionModel.Primary as RowSelectionModel;
            foreach (SelectedRow row in sm.SelectedRows)
            {
                t203 _t203 = new t203();
                _t203.t203_00 = row.RecordID;//int.Parse(row.RecordID);
                if (mgr.Del_t203(_t203))
                {
                    log.Debug("t203中执行了删除，并成功");
                    X.Msg.Notify("成功", "<font color='green'>已经成功删除选中的记录</font>").Show();
                }
                else
                    X.Msg.Notify("失败", "<font color='green'>删除记录失败，请您重试！</font>").Show();
            }
            t203_Grid.Reload();
        }
        protected void BtnSave_Click(object sender, DirectEventArgs e)
        {
            t203Mgr mgr = new t203Mgr();
            t203 _t203 = new t203();
            if (Hid.Text.Length > 0)
                _t203 = mgr.FindById_t203(int.Parse(Hid.Text));
            
			_t203.t203_01 = Txtt203_01.Text.Trim();
			_t203.t203_71 = Txtt203_71.Text.Trim();
			_t203.t203_72 = Txtt203_72.Text.Trim();
			_t203.t203_02 = Txtt203_02.Text.Trim();
			_t203.t203_73 = Txtt203_73.Text.Trim();
			_t203.t203_74 = Txtt203_74.Text.Trim();
			_t203.t203_75 = Txtt203_75.Text.Trim();
			_t203.t203_03 = Txtt203_03.Text.Trim();
			_t203.t203_76 = Txtt203_76.Text.Trim();
			_t203.t203_77 = Txtt203_77.Text.Trim();
			_t203.t203_78 = Txtt203_78.Text.Trim();
			_t203.t203_79 = Txtt203_79.Text.Trim();
			_t203.t203_80 = Txtt203_80.Text.Trim();
			_t203.t203_81 = Txtt203_81.Text.Trim();
			_t203.t203_82 = Txtt203_82.Text.Trim();
			_t203.t203_04 = Txtt203_04.Text.Trim();
			_t203.t203_83 = Txtt203_83.Text.Trim();
			_t203.t203_05 = Txtt203_05.Text.Trim();
			_t203.t203_84 = Txtt203_84.Text.Trim();
			_t203.t203_85 = Txtt203_85.Text.Trim();
			_t203.t203_86 = Txtt203_86.Text.Trim();
			_t203.t203_87 = Txtt203_87.Text.Trim();
			_t203.t203_06 = Txtt203_06.Text.Trim();
			_t203.t203_88 = Txtt203_88.Text.Trim();
			_t203.t203_89 = Txtt203_89.Text.Trim();
			_t203.t203_90 = Txtt203_90.Text.Trim();
			_t203.t203_91 = Txtt203_91.Text.Trim();
			_t203.t203_92 = Txtt203_92.Text.Trim();
			_t203.t203_138 = Txtt203_138.Text.Trim();
			_t203.t203_93 = Txtt203_93.Text.Trim();
			_t203.t203_07 = Txtt203_07.Text.Trim();
			_t203.t203_94 = Txtt203_94.Text.Trim();
			_t203.t203_95 = Txtt203_95.Text.Trim();
			_t203.t203_96 = Txtt203_96.Text.Trim();
			_t203.t203_97 = Txtt203_97.Text.Trim();
			_t203.t203_98 = Txtt203_98.Text.Trim();
			_t203.t203_99 = Txtt203_99.Text.Trim();
			_t203.t203_100 = Txtt203_100.Text.Trim();
			_t203.t203_101 = Txtt203_101.Text.Trim();
			_t203.t203_102 = Txtt203_102.Text.Trim();
			_t203.t203_103 = Txtt203_103.Text.Trim();
			_t203.t203_104 = Txtt203_104.Text.Trim();
			_t203.t203_105 = Txtt203_105.Text.Trim();
			_t203.t203_106 = Txtt203_106.Text.Trim();
			_t203.t203_107 = Txtt203_107.Text.Trim();
			_t203.t203_108 = Txtt203_108.Text.Trim();
			_t203.t203_109 = Txtt203_109.Text.Trim();
			_t203.t203_110 = Txtt203_110.Text.Trim();
			_t203.t203_111 = Txtt203_111.Text.Trim();
			_t203.t203_112 = Txtt203_112.Text.Trim();
			_t203.t203_113 = Txtt203_113.Text.Trim();
			_t203.t203_114 = Txtt203_114.Text.Trim();
			_t203.t203_115 = Txtt203_115.Text.Trim();
			_t203.t203_116 = Txtt203_116.Text.Trim();
			_t203.t203_117 = Txtt203_117.Text.Trim();
			_t203.t203_118 = Txtt203_118.Text.Trim();
			_t203.t203_119 = Txtt203_119.Text.Trim();
			_t203.t203_120 = Txtt203_120.Text.Trim();
			_t203.t203_121 = Txtt203_121.Text.Trim();
			_t203.t203_122 = Txtt203_122.Text.Trim();
			_t203.t203_123 = Txtt203_123.Text.Trim();
			_t203.t203_124 = Txtt203_124.Text.Trim();
			_t203.t203_125 = Txtt203_125.Text.Trim();
			_t203.t203_126 = Txtt203_126.Text.Trim();
			_t203.t203_127 = Txtt203_127.Text.Trim();
			_t203.t203_128 = Txtt203_128.Text.Trim();
			_t203.t203_08 = Txtt203_08.Text.Trim();
			_t203.t203_129 = Txtt203_129.Text.Trim();
			_t203.t203_130 = Txtt203_130.Text.Trim();
			_t203.t203_131 = Txtt203_131.Text.Trim();
			_t203.t203_132 = Txtt203_132.Text.Trim();
			_t203.t203_133 = Txtt203_133.Text.Trim();
			_t203.t203_134 = Txtt203_134.Text.Trim();
			_t203.t203_135 = Txtt203_135.Text.Trim();
			_t203.t203_136 = Txtt203_136.Text.Trim();
			_t203.t203_137 = Txtt203_137.Text.Trim();
			_t203.t203_09 = Txtt203_09.Text.Trim();
			_t203.t203_70 = Txtt203_70.Text.Trim();
			_t203.t203_10 = Txtt203_10.Text.Trim();
			_t203.t203_11 = Txtt203_11.Text.Trim();
			_t203.t203_12 = Txtt203_12.Text.Trim();
			_t203.collection_time = Txtcollection_time.Text.Trim();

            bool isok = false;
            if (Hid.Text.Length > 0)
                isok = mgr.Update_t203(_t203);
            else
                isok = mgr.Add_t203(_t203);
            if (isok)
            {
                t203_Win.Hide();
                X.Msg.Notify("成功", "<font color='green'>恭喜您，操作成功！</font>").Show();
                log.Debug("t203中执行了保存（插入或修改），并成功");
                t203_Grid.Reload();
            }
            else
                X.Msg.Notify("失败", "<font color='red'>操作失败，请您重试！</font>").Show();
        }
        //数据保存为Excel
        protected void BtnSaveToExcel(object sender, EventArgs e)
        {
            string json = ExcelGridData.Value.ToString();
            StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
            XmlNode xml = eSubmit.Xml;
            this.Response.Clear();
            this.Response.ContentType = "application/vnd.ms-excel";
            this.Response.AddHeader("Content-Disposition", "attachment; filename=QiDian10Excel.xls");
            XslCompiledTransform xtExcel = new XslCompiledTransform();
            xtExcel.Load(Server.MapPath("/View/ExcelTemp/Excel.xsl"));
            xtExcel.Transform(xml, null, this.Response.OutputStream);
            this.Response.End();

        }
    }
}